import 'package:bluetooth_protocols_parser_plugin/library.dart';
import 'package:safemap/safemap.dart';

abstract class BaseModel {
  // 通过 map 转换成对象
  Map<String, dynamic> toMap();
}

// 固件信息模型
class FirmwareInfoModel extends BaseModel {
  // 设备号
  int deviceId = 0;

  // 应用程序版本号
  String appVersion = "";

  // 引导程序版本号
  String bootVersion = '';

  // 设备类型名称
  String deviceTypeName = "";

  FirmwareInfoModel.fromMap(Map<String, dynamic> map, {bool isLR1 = false}) {
    SafeMap safeMap = SafeMap(map);
    deviceId = safeMap['device_id'].toInt ?? 0;
    appVersion = safeMap['app_version'].string ?? '';
    bootVersion = safeMap['boot_version'].string ?? '';
    deviceTypeName =
        TargetDeviceType.getTypeByNum(deviceId, isLR1 ? 1 : 0)?.name ?? "";
  }

  @override
  Map<String, dynamic> toMap() {
    return {
      'device_id': deviceId,
      'app_version': appVersion,
      'boot_version': bootVersion,
      'device_type_name': deviceTypeName,
    };
  }
}
